#include "sweety_3D_Material.h"
#include "tools/sweety_ProgramObject.h"
#include "backends/sweety_Impl_opengl3_loader.h"


namespace SW
{
	Material::Material()
	{

	}

	Material::~Material()
	{

	}

	void Material::Sampler(MainProgramObj* shader, const char* diffuse_path, const char* specular_path, float shininess)
	{
		SW_ASSERT(diffuse_path && specular_path && shader);

		SwTexture texture = SW::CreateTexture(diffuse_path);
		m_SamplerMap[SamplerType::DIFFUSE] = (int)texture.textureId;

		texture = SW::CreateTexture(specular_path);
		m_SamplerMap[SamplerType::SPECULAR] = (int)texture.textureId;

		m_Shininess = shininess;
	}

	void Material::Set(MainProgramObj* shader, const char* name, SamplerType type)
	{
		SW_ASSERT(name && shader);
		glUniform1i(shader->getUniformLocation(name), (int)type);
	}
	
	void Material::Bind(SamplerType type)
	{		
		glActiveTexture(GL_TEXTURE0 + (int)type);
		glBindTexture(GL_TEXTURE_2D, m_SamplerMap[type]);
	}

	void Material::SetShininess(MainProgramObj* shader, const char* name, float shininess)
	{
		SW_ASSERT(name && shader);
		m_Shininess = shininess;
		glUniform1f(shader->getUniformLocation(name), shininess);
	}
}